package common.commands;

import java.util.Hashtable;

import common.Commands;

public class CommandHelp implements ICommand {

	@Override
	public String getName() {
		
		return "help";
	}

	@Override
	public String getSynopsis() {
		
		return "help [command]";
	}

	@Override
	public CommandValue run(String arg) {
		
		Hashtable<String, ICommand> commands = Commands.getCommands();
		
		if (arg.length() == 0) {
			System.out.println("Help:");
			for (ICommand cmd : commands.values()) {
				System.out.println(cmd.getName() + " : " + cmd.help());
			}
		} else {
			
			ICommand cmd = commands.get(arg.toUpperCase());
			
			if (cmd != null) {
				System.out.println(cmd.getName() + " : " + cmd.help());
			} else {
				System.out.println("Help: Unknown command " + arg);
			}
		}
		
		return CommandValue.OK;
	}

	@Override
	public String help() {
		
		return "Display the help of each commands";
	}

}
